package main

import (
	"fmt"
	"sync"
	"time"
)

/*
Once 的作用是多次调用但只执行一次
*/
func main() {
	o := &sync.Once{}
	go myfun(o)
	go myfun(o)
	time.Sleep(time.Second * 2)
}

func myfun(o *sync.Once) {
	fmt.Println("Begin function")

	o.Do(func() {
		fmt.Println("Working...")
	})
	fmt.Println("Function end")
}
